<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="__STATIC__/js/jquery.js"></script>
    <script src="__STATIC__/layui/layui.js"></script>
    <script src="__STATIC__/bootstrap-table/js/bootstrap-table.js"></script>
    <script src="__STATIC__/bootstrap-table/js/bootstrap-table-zh-CN.min.js"></script>
    <script src="__STATIC__/bootstrap-table/js/dropdown.js"></script>
    <link rel="stylesheet" href="__STATIC__/bootstrap-table/css/bootstrap-table.min.css">
    <link rel="stylesheet" href="__STATIC__/bootstrap-table/css/bootstrap.css">
    <script type="text/javascript" src="__STATIC__/x-admin/js/xadmin.js"></script>
    <link rel="stylesheet" href="__STATIC__/x-admin/css/font.css">
    <link rel="stylesheet" href="__STATIC__/x-admin/css/xadmin.css">
</head>
<body>
<br>

<a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
    <i class="layui-icon" style="line-height:30px">ဂ</i></a>
<div class="layui-row">
    <form class="layui-form layui-col-md12 x-so" onsubmit="return false">
        <input type="text" name="username"  placeholder="请输入评论人的姓名" autocomplete="off" class="layui-input">
        <button class="layui-btn"  id="search"><i class="layui-icon">&#xe615;</i></button>
    </form>
</div>
<table id="adminList">

</table>
</body>
</html>
<script>
    $('#adminList').bootstrapTable({
        //获取行号
        language: 'zh-CN',
        autoclose: true,
        todayHighlight: true,
        striped: true,//设置为 true 会有隔行变色效果
        method: 'post',//服务器数据的请求方式 'get' or 'post'
        url: "{:url('/feedBack/feedBackList')}",//服务器数据的加载地址
        toolbar:'#toolbar',//
        searchOnEnterKey:true,
        sortName:'ID',//排序字段
        sortOrder : 'desc',//降序
        sidePagination: "server",   //分页方式：client客户端分页，server服务端分页（*）
        pagination: 'false',//设置为 true 会在表格底部显示分页条
        clickToSelect:'true',//设置true 将在点击行时，自动选择rediobox 和 checkbox
        singleSelect:'true',//设置True 将禁止多选
        pageSize: '15',//如果设置了分页，页面数据条数
        pageList:[15,30,50],
        smartDisplay:false,
        //得到查询的参数
        queryParams : function (params){
            //这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的
            var temp = {
                rows: params.limit,                         //页面大小
                page: (params.offset / params.limit) + 1,   //页码
                sort: params.sort,      //排序列名
                sortOrder: params.order,//排位命令（desc，asc）
                searchName:$("input[name=username]").val(),
            };
            return temp;
        },
        columns: [
            //{title:'请选择',align:'center',checkbox : true},
            {field: 'id', title: 'ID', align:'center'},
            {field: 'title', title: '标题', align:'center'},
            {formatter:personalName, title: '反馈人', align:'center'},
            {formatter:personalType, title: '反馈人类别', align:'center'},
            {field:'type', title: '问题类别', align:'center'},
            {formatter:state, title: '状态', align:'center'},
            {formatter:operateFormatter,title:"操作",align:'center'}
        ]
    })
    //反馈人姓名
    function personalName(val,rows) {
        switch (rows.status) {
            case 1:return rows.teacher.teacher_name;
            case 2:return rows.school.school_name;
            case 3:return '手机APP';
        }
    }
    //反馈人类别
    function personalType(val,rows) {
        switch (rows.status) {
            case 1:return '教师';
            case 2:return '<span style="color: blue">学校管理员</span>';
            case 3:return '<span style="color: red">手机APP</span>';
        }
    }
    //是否已回复
    function state(val,rows) {
        return rows.state == 1 ? '<span style="color: red">未回复</span>' : '已回复';
    }
    //操作按钮
    function operateFormatter(val,rows){
        if(rows.state == 1){
            return [
                "<button type='button' onclick='detail("+rows.id+")' class='btn btn-info btn-xs'>详情</button>&nbsp;&nbsp;",
                "<button type='button' onclick='reply("+rows.id+")' class='btn btn-primary btn-xs'>回复</button>&nbsp;&nbsp;",
                "<button type='button' onclick='del("+rows.id+")' class='btn btn-danger btn-xs'>删除</button>&nbsp;&nbsp;"
            ].join('');
        }else{
            return [
                "<button type='button' onclick='detail("+rows.id+")' class='btn btn-info btn-xs'>详情</button>&nbsp;&nbsp;",
                "<button type='button' style='visibility: hidden' class='btn btn-primary btn-xs'>回复</button>&nbsp;&nbsp;",
                "<button type='button' onclick='del("+rows.id+")' class='btn btn-danger btn-xs'>删除</button>&nbsp;&nbsp;"
            ].join('');
        }
    }
    //详情
    function detail(id) {
        layer.open({
            type:2,
            title:"详情",
            area:['600px','500px'],
            content:"/feedBack/detail?id="+id
        });
    }
    //回复
    function reply(id) {
        layer.open({
            type:2,
            title:"回复",
            area:['600px','300px'],
            content:"/feedBack/before_reply?id="+id
        });
    }
    //删除
    function del(id) {
        layer.confirm('你确定要删除吗',{btn:['确定','取消']},function () {
            $.ajax({
                url:"/feedback/delete",
                type:"post",
                dataType:"json",
                data:{
                    id:id
                },
                success:function (res) {
                    if(res.code){
                        layer.msg(res.msg,{icon:1,time:2000});
                        $("#adminList").bootstrapTable('remove',{
                            field:'id',
                            values:[parseInt(id)]
                        })
                    }else{
                        layer.msg(res.msg,{icon:5,time:2000});
                    }
                }
            });
        })
    }
    //检索操作
    $("#search").click(function(){
        $("#adminList").bootstrapTable(('refresh'));
    })
</script>